package com.edfu.commons.email.entities;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * @author naresred
 *
 */
@Entity
@Table(name = "EMAIL_TEMPLATE")
public class EmailTemplateEntity implements Serializable {

	private static final long serialVersionUID = -8523279627387416310L;
	
	@Id
	@Column(name = "ID")
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;
	
	@Column(name = "NAME", length = 60, nullable = false)
	private String name;
	
	@Column(name = "DESCRIPTION", length = 300, nullable = true)
	private String description;
	
	@Lob
	@Column(name = "CONTENT", length=50000, nullable = false)
	private String content;
	
	@Column(name = "LOCALE", length = 60, nullable = false)
	private String locale;
	
	@Column(name = "ACTIVE", length = 1, nullable = false)
	private int active = 1;
	
	@Column(name = "DEFAULTTEMPLATE", length = 1, nullable = false)
	private int defaultTemplate;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "EVENTID", nullable = false)
	private EmailEventEntity emailEvent;

	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}	

	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}

	public String getLocale() {
		return locale;
	}
	public void setLocale(String locale) {
		this.locale = locale;
	}

	public int getActive() {
		return active;
	}
	public void setActive(int active) {
		this.active = active;
	}	

	public int getDefaultTemplate() {
		return defaultTemplate;
	}
	public void setDefaultTemplate(int defaultTemplate) {
		this.defaultTemplate = defaultTemplate;
	}

	public EmailEventEntity getEmailEvent() {
		return emailEvent;
	}
	public void setEmailEvent(EmailEventEntity emailEvent) {
		this.emailEvent = emailEvent;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((locale == null) ? 0 : locale.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		
		EmailTemplateEntity other = (EmailTemplateEntity) obj;
		if (locale == null) {
			if (other.locale != null) {
				return false;
			}
		} else if (!locale.equals(other.locale)) {
			return false;
		}
		if (name == null) {
			if (other.name != null) {
				return false;
			}
		} else if (!name.equals(other.name)) {
			return false;
		}
		
		return true;
	}

	@Override
	public String toString() {
		return "EmailTemplateEntity [id=" + id + ", name=" + name + ", locale="+ locale + ", active=" + active + "]";
	}	 

}
